package com.hh.m15e.utils;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.hh.m15e.constant.HttpUrl;
import com.hh.m15e.domain.dto.SignIn;
import com.hh.m15e.domain.dto.Signinoutb;
import com.hh.m15e.domain.vo.InputParamVo;
import com.hh.m15e.domain.vo.OutputParamVo;

/**
 * 作者: Ⅹ玖
 * 创建日期：2025/2/21 14:33
 * 文档描述：接口的调用
 */
//@Component
public class CallsAPIUtil {
    /**
     * 9001接口调用
     * @param signIn 入参
     * @return Signinoutb
     */
    public Signinoutb callApi9001(SignIn signIn){
        if(signIn == null) System.err.println("入参为空");;
        Signinoutb signinoutb = JSONUtil.toBean(HttpUtil.post(HttpUrl.URL_9001, JSONUtil.toJsonStr(signIn)), Signinoutb.class);
        if (signinoutb == null) System.err.println("9001接口调用失败");;
        return signinoutb;
    }

    /**
     * 通用Api请求
     * @param url 请求地址
     * @param inputParamVo 请求体
     * @return OutputParamVo
     */
    public OutputParamVo callApi(String url,InputParamVo inputParamVo){
        if(inputParamVo.getInput() == null) System.err.println("入参为空");
        String postResult = HttpUtil.post(url, JSONUtil.toJsonStr(inputParamVo));
        if(postResult == null) System.err.println("接口调用失败");
        return JSONUtil.toBean(postResult, OutputParamVo.class);
    }

    /**
     * 封装请求参数报文格式
     * @param param 请求体JSON字符串
     * @return InputParamVo
     */
    public InputParamVo getInputParamVo(String param,String signNo){
        InputParamVo inputParamVo = new InputParamVo();
        inputParamVo.setInput(param);
        inputParamVo.setSignNo(signNo);
        return inputParamVo;
    }




}
